<?
Class GalleryModule{
    var $_connect;
    var $error;
    function GalleryModule() {
        $this->_connect = new Dataconnection();
    }
    function geterror(){
        return $this->error;
    }
    function get($id){
        $SQLCommand="
        SELECT
            `album`.*
        FROM
            `album`
            
        WHERE
            `album`.`id`='$id'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        $result=array();
        if($data!=null ){
            $result=$data->fetch_array();
            return $result;
        }
        return null;
    }
    function getDetail($id){
        $SQLCommand="
        SELECT
            `albumdetail`.*,
            `album`.`title` as albumtitle
            
        FROM
            `albumdetail`,`album`
            
        WHERE
            `album`.`id`=`albumdetail`.`album`
            AND `album`.`id`='$id'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    function gets(){
        $SQLCommand="
        SELECT
            count(`albumdetail`.`id`) as `amount`,
            `album`.*
        FROM
            `album` left join `albumdetail` on `albumdetail`.`album`=`album`.id
        GROUP BY `album`.`id`    
        ORDER BY `album`.`title`
            
        ";
        
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    function insert($name){
        
        $SQLCommand="
        INSERT 
            `album`(
                `album`,`insert`
            )
            VALUE(
                '$name',now()
            )
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function update($id,$name){
        $SQLCommand="
        UPDATE 
            `album`
        SET `album`='$name',
            
            `update`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function delete($id){
        $SQLCommand="
        UPDATE 
            `album`
        SET `delete`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function restore($id){
        $SQLCommand="
        UPDATE 
            `album`
        SET `delete`=null
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function insertimg($albumid,$img){
        
        $SQLCommand="
        INSERT 
            `albumdetail`(
                `album`,`image`,`insert`
            )
            VALUE(
                '$albumid','$img',now()
            )
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function updateimg($id,$img){
        $SQLCommand="
        UPDATE 
            `albumdetail`
        SET `image`='$img',  
            `update`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function deleteimg($id){
        $SQLCommand="
        UPDATE 
            `albumdetail`
        SET `delete`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function restoreimg($id){
        $SQLCommand="
        UPDATE 
            `albumdetail`
        SET `delete`=null
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
}
?>